package com.xnengine.bondobongo.entity;

//import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.xnengine.bondobongo.ResourcesManager;

/**
 * ɽ
 * 
 * @author 158359999
 * 
 */
public class Hill extends Actor {

	TextureRegion texture;
	Camera cam;

	Vector3 camLastLocation = new Vector3();
	Vector3 camCurLocation = new Vector3();
	Vector3 tmpLocation = new Vector3();
	float cw;

	public Hill(String name, Camera c) {
		super(name);
		cam = c;
		texture = ResourcesManager.getTextureRegion(ResourcesManager.GAME_STAGE, "hill");
		this.width = texture.getRegionWidth();
		this.height = texture.getRegionHeight();
		this.originX = this.width / 2;
		this.originY = this.height / 2;
		cw = cam.viewportWidth / 2;
		camLastLocation.set(cam.position);
		camCurLocation.set(cam.position);
	}

	public void reSet() {
		camLastLocation.set(cam.position);
		camCurLocation.set(cam.position);
	}

	@Override
	public void act(float delta) {
		super.act(delta);

		if (x + width < cam.position.x - cw) {
			x += width * 2;
			//Gdx.app.log("Hill", "1");
		} else if (x < cam.position.x + cw) {
			camCurLocation.set(cam.position);
			tmpLocation.set(camCurLocation.sub(camLastLocation));
			x += tmpLocation.x * 0.4f;
			camLastLocation.set(cam.position);
			//Gdx.app.log("Hill", "name:" + this.name + "		2		x:" + x + "	camx:" + tmpLocation.x);
		}
	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		batch.draw(texture, x, y);
	}

	@Override
	public boolean touchDown(float x, float y, int pointer) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void touchUp(float x, float y, int pointer) {
		// TODO Auto-generated method stub

	}

	@Override
	public void touchDragged(float x, float y, int pointer) {
		// TODO Auto-generated method stub

	}

	@Override
	public Actor hit(float x, float y) {
		// TODO Auto-generated method stub
		return null;
	}

}
